package com.example.pluto.common.models;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * @Description : Ret
 * @Author : Mr.Yang
 * @Date : 2022/8/17 15:10
 * @Version : 1.0
 **/
@Data
@AllArgsConstructor
public class Ret<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private static int FAIL = 500;
    private static int SUCCESS = 200;


    /**
     * 0=success
     */
    private int code = SUCCESS;
    private String msg;
    private T data;

    public Ret() {
    }

    public Ret(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Ret(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public Ret(T data) {
        this.data = data;
    }


    public static <T> Ret<T> error(int code, String msg, T data) {
        return new Ret<>(code, msg, data);
    }

    public static <T> Ret<T> error(String msg, T data) {
        return new Ret<>(FAIL, msg, data);
    }

    public static <T> Ret<T> error(String msg) {
        return new Ret<>(FAIL, msg);
    }

    public static <T> Ret<T> success(String msg, T data) {
        return new Ret<>(SUCCESS, msg, data);
    }

    public static <T> Ret<T> success(T data) {
        return new Ret<>(SUCCESS, "请求成功", data);
    }

    public static <T> Ret<T> success() {
        return new Ret<>(SUCCESS, "请求成功", null);
    }
}
